<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-169911533-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-169911533-1');
</script>

  

  
  <title>JavaScript使用 Web Serial API获取串行设备端口数据(地磅串口数据) | 空城盼故人</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="google-site-verification" content="NOVpqBhVVjZHOamocUf3Grijt7xAK_Engoe_FNrxE3Q" />
  <meta name="baidu-site-verification" content="HBrapLOndy" />
  
  <meta name="keywords" content="许嵩老公" />
  
  <meta name="description" content="前期准备 资源链接 代码示例 检查浏览器是否支持 打开串行端口   地磅读数代码示例 chrome浏览器配置在http协议使用web串行api">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript使用 Web Serial API获取串行设备端口数据(地磅串口数据)">
<meta property="og:url" content="https://xiaoyan94.github.io/2022/11/18/JavaScript%E4%BD%BF%E7%94%A8-Web-Serial-API%E8%8E%B7%E5%8F%96%E4%B8%B2%E8%A1%8C%E8%AE%BE%E5%A4%87%E7%AB%AF%E5%8F%A3%E6%95%B0%E6%8D%AE-%E5%9C%B0%E7%A3%85%E4%B8%B2%E5%8F%A3%E6%95%B0%E6%8D%AE/index.html">
<meta property="og:site_name" content="空城盼故人">
<meta property="og:description" content="前期准备 资源链接 代码示例 检查浏览器是否支持 打开串行端口   地磅读数代码示例 chrome浏览器配置在http协议使用web串行api">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://xiaoyan94.github.io/2022/11/18/JavaScript%E4%BD%BF%E7%94%A8-Web-Serial-API%E8%8E%B7%E5%8F%96%E4%B8%B2%E8%A1%8C%E8%AE%BE%E5%A4%87%E7%AB%AF%E5%8F%A3%E6%95%B0%E6%8D%AE-%E5%9C%B0%E7%A3%85%E4%B8%B2%E5%8F%A3%E6%95%B0%E6%8D%AE/2023-02-08-10-58-04.png">
<meta property="og:image" content="https://xiaoyan94.github.io/2022/11/18/JavaScript%E4%BD%BF%E7%94%A8-Web-Serial-API%E8%8E%B7%E5%8F%96%E4%B8%B2%E8%A1%8C%E8%AE%BE%E5%A4%87%E7%AB%AF%E5%8F%A3%E6%95%B0%E6%8D%AE-%E5%9C%B0%E7%A3%85%E4%B8%B2%E5%8F%A3%E6%95%B0%E6%8D%AE/2023-02-08-10-59-40.png">
<meta property="article:published_time" content="2022-11-18T13:10:15.000Z">
<meta property="article:modified_time" content="2023-02-09T09:44:16.815Z">
<meta property="article:author" content="许嵩老公">
<meta property="article:tag" content="JavaScript">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://xiaoyan94.github.io/2022/11/18/JavaScript%E4%BD%BF%E7%94%A8-Web-Serial-API%E8%8E%B7%E5%8F%96%E4%B8%B2%E8%A1%8C%E8%AE%BE%E5%A4%87%E7%AB%AF%E5%8F%A3%E6%95%B0%E6%8D%AE-%E5%9C%B0%E7%A3%85%E4%B8%B2%E5%8F%A3%E6%95%B0%E6%8D%AE/2023-02-08-10-58-04.png">
  
    <link rel="alternate" href="../../../../atom.xml" title="空城盼故人" type="application/atom+xml">
  
  
    <link rel="icon" href="https://q1.qlogo.cn/g?b=qq&nk=979727728&s=640">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="../../../../css/style.css">

  
<link rel="stylesheet" href="../../../../css/highlight.css">

<meta name="generator" content="Hexo 4.2.1"></head>

<body>
  <div id="fullpage" class="mobile-nav-right">
    <div class="fixed"></div>
    
      <div id="wrapper">
    
    
      <header id="header">
  <div id="nav-toggle" class="nav-toggle"></div>
  <div class="head-box global-width">
    <nav class="nav-box nav-right">
      
        <a class="nav-item" href="../../../../index.html" title
        
        >首页</a>
      
        <a class="nav-item" href="../../../../archives" title
        
        >归档</a>
      
        <a class="nav-item" href="../../../../quick-notes" title
        
        >小抄</a>
      
        <a class="nav-item" href="../../../../about" title
        
        >关于</a>
      
    </nav>
  </div>
</header>
      <div id="middlecontent" title class="global-width sidebar-right">
        <section id="main"><article id="post-JavaScript使用-Web-Serial-API获取串行设备端口数据-地磅串口数据" class="article global-container article-type-post" itemscope itemprop="blogPost">
  
    <header class="article-header">
      
  
    <h1 class="article-title" itemprop="name">
      JavaScript使用 Web Serial API获取串行设备端口数据(地磅串口数据)
    </h1>
  

    </header>
  
  <div class="article-meta">
    <a href="" class="article-date">
  <time datetime="2022-11-18T13:10:15.000Z" itemprop="datePublished">2022-11-18</time>
</a>
    
    
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="../../../../tags/JavaScript/" rel="tag">JavaScript</a></li></ul>

  </div>
  
    <span id="busuanzi_container_page_pv">
      本文总阅读量<span id="busuanzi_value_page_pv"></span>次
    </span>
  

  <div class="article-inner">
    
    <div class="article-content article-content-cloud" itemprop="articleBody">
      
        
        <ul>
<li><a href="#%E5%89%8D%E6%9C%9F%E5%87%86%E5%A4%87">前期准备</a></li>
<li><a href="#%E8%B5%84%E6%BA%90%E9%93%BE%E6%8E%A5">资源链接</a></li>
<li><a href="#%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B">代码示例</a><ul>
<li><a href="#%E6%A3%80%E6%9F%A5%E6%B5%8F%E8%A7%88%E5%99%A8%E6%98%AF%E5%90%A6%E6%94%AF%E6%8C%81">检查浏览器是否支持</a></li>
<li><a href="#%E6%89%93%E5%BC%80%E4%B8%B2%E8%A1%8C%E7%AB%AF%E5%8F%A3">打开串行端口</a></li>
</ul>
</li>
<li><a href="#%E5%9C%B0%E7%A3%85%E8%AF%BB%E6%95%B0%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B">地磅读数代码示例</a></li>
<li><a href="#chrome%E6%B5%8F%E8%A7%88%E5%99%A8%E9%85%8D%E7%BD%AE%E5%9C%A8http%E5%8D%8F%E8%AE%AE%E4%BD%BF%E7%94%A8web%E4%B8%B2%E8%A1%8Capi">chrome浏览器配置在http协议使用web串行api</a></li>
</ul>
<a id="more"></a>

<h2 id="前期准备"><a href="#前期准备" class="headerlink" title="前期准备"></a>前期准备</h2><ol>
<li>学习 <strong>Web Serial API</strong></li>
<li>下载串口模拟工具 VSPD，用于建立虚拟串口对</li>
<li>下载串口调试精灵，用于调试，包括打开、关闭串口，发送、接收数据等</li>
<li>编写 js 代码，读取串口数据</li>
</ol>
<h2 id="资源链接"><a href="#资源链接" class="headerlink" title="资源链接"></a>资源链接</h2><ol>
<li><a href="https://cn.bing.com/search?q=VSPD" target="_blank" rel="noopener">VSPD</a></li>
<li><a href="https://cn.bing.com/search?q=%E4%B8%B2%E5%8F%A3%E8%B0%83%E8%AF%95%E7%B2%BE%E7%81%B5" target="_blank" rel="noopener">串口调试精灵</a></li>
<li><a href="https://cn.bing.com/search?q=Chrome%20Web%20Serial%20API" target="_blank" rel="noopener">Web Serial API</a></li>
</ol>
<h2 id="代码示例"><a href="#代码示例" class="headerlink" title="代码示例"></a>代码示例</h2><h3 id="检查浏览器是否支持"><a href="#检查浏览器是否支持" class="headerlink" title="检查浏览器是否支持"></a>检查浏览器是否支持</h3><p>只有浏览器支持 <strong>Web Serial API</strong> 才能通过 JavaScript 代码访问串口设备。要检查是否支持 Web Serial API，请使用：</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="false"data-rel="JAVASCRIPT"><figure class="iseeu highlight /javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (<span class="string">"serial"</span> <span class="keyword">in</span> navigator) &#123;</span><br><span class="line">  <span class="comment">// 支持 Web 串行 API。</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>

<h3 id="打开串行端口"><a href="#打开串行端口" class="headerlink" title="打开串行端口"></a>打开串行端口</h3><p>Web Serial API 在设计上是异步的。这可以防止网站 UI 在等待输入时阻塞。要打开串行端口，首先访问一个 SerialPort 对象。为此，可以通过调用 <code>navigator.serial.requestPort()</code> 以响应用户手势（例如触摸或鼠标单击）来提示用户选择单个串行端口，或者从返回的 <code>navigator.serial.getPorts()</code> 中选择一个网站已被授予访问权限的串行端口列表。</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="false"data-rel="JAVASCRIPT"><figure class="iseeu highlight /javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">document</span>.querySelector(<span class="string">'button'</span>).addEventListener(<span class="string">'click'</span>, <span class="keyword">async</span> () =&gt; &#123;</span><br><span class="line">  <span class="comment">// 提示用户选择任意串口。</span></span><br><span class="line">  <span class="keyword">const</span> port = <span class="keyword">await</span> navigator.serial.requestPort();</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></div>

<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="false"data-rel="JAVASCRIPT"><figure class="iseeu highlight /javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 获取用户之前授予网站访问权限的所有串行端口。</span></span><br><span class="line"><span class="keyword">const</span> ports = <span class="keyword">await</span> navigator.serial.getPorts();</span><br></pre></td></tr></table></figure></div>

<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="false"data-rel="JAVASCRIPT"><figure class="iseeu highlight /javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 提示用户选择任意串口。</span></span><br><span class="line"><span class="keyword">const</span> port = <span class="keyword">await</span> navigator.serial.requestPort();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 等待串口打开。波特率 9600</span></span><br><span class="line"><span class="keyword">await</span> port.open(&#123; <span class="attr">baudRate</span>: <span class="number">9600</span> &#125;);</span><br></pre></td></tr></table></figure></div>

<p>还可以在打开串行端口时指定以下任何选项。这些选项是可选的，<a href="https://wicg.github.io/serial/#serialoptions-dictionary" target="_blank" rel="noopener">查看默认值</a>。</p>
<ul>
<li><code>dataBits</code>: 每帧的数据位数（7 或 8）。</li>
<li><code>stopBits</code>: 帧末尾的停止位数（1 或 2）。</li>
<li><code>parity</code>: 奇偶校验模式（<code>&quot;none&quot;</code>, <code>&quot;even&quot;</code> 或者 <code>&quot;odd&quot;</code>）。</li>
<li><code>bufferSize</code>: 应创建的读写缓冲区的大小（必须小于 16MB）。</li>
<li><code>flowControl</code>：流量控制模式（<code>&quot;none&quot;</code> 或 <code>&quot;hardware&quot;</code>）。</li>
</ul>
<h2 id="地磅读数代码示例"><a href="#地磅读数代码示例" class="headerlink" title="地磅读数代码示例"></a>地磅读数代码示例</h2><div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="false"data-rel="JAVASCRIPT"><figure class="iseeu highlight /javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br><span class="line">552</span><br><span class="line">553</span><br><span class="line">554</span><br><span class="line">555</span><br><span class="line">556</span><br><span class="line">557</span><br><span class="line">558</span><br><span class="line">559</span><br><span class="line">560</span><br><span class="line">561</span><br><span class="line">562</span><br><span class="line">563</span><br><span class="line">564</span><br><span class="line">565</span><br><span class="line">566</span><br><span class="line">567</span><br><span class="line">568</span><br><span class="line">569</span><br><span class="line">570</span><br><span class="line">571</span><br><span class="line">572</span><br><span class="line">573</span><br><span class="line">574</span><br><span class="line">575</span><br><span class="line">576</span><br><span class="line">577</span><br><span class="line">578</span><br><span class="line">579</span><br><span class="line">580</span><br><span class="line">581</span><br><span class="line">582</span><br><span class="line">583</span><br><span class="line">584</span><br><span class="line">585</span><br><span class="line">586</span><br><span class="line">587</span><br><span class="line">588</span><br><span class="line">589</span><br><span class="line">590</span><br><span class="line">591</span><br><span class="line">592</span><br><span class="line">593</span><br><span class="line">594</span><br><span class="line">595</span><br><span class="line">596</span><br><span class="line">597</span><br><span class="line">598</span><br><span class="line">599</span><br><span class="line">600</span><br><span class="line">601</span><br><span class="line">602</span><br><span class="line">603</span><br><span class="line">604</span><br><span class="line">605</span><br><span class="line">606</span><br><span class="line">607</span><br><span class="line">608</span><br><span class="line">609</span><br><span class="line">610</span><br><span class="line">611</span><br><span class="line">612</span><br><span class="line">613</span><br><span class="line">614</span><br><span class="line">615</span><br><span class="line">616</span><br><span class="line">617</span><br><span class="line">618</span><br><span class="line">619</span><br><span class="line">620</span><br><span class="line">621</span><br><span class="line">622</span><br><span class="line">623</span><br><span class="line">624</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> $ = <span class="built_in">window</span>.$;</span><br><span class="line">$find = <span class="built_in">window</span>.$find;</span><br><span class="line">$(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (!(<span class="string">"serial"</span> <span class="keyword">in</span> navigator)) &#123;</span><br><span class="line">        alertError(<span class="string">"无法使用"</span>, <span class="string">"该浏览器不支持读取串口设备，请更换Chrome浏览器！"</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 设置全局变量</span></span><br><span class="line">    <span class="built_in">window</span>.weightValues = []; <span class="comment">//存储最近三次称重值</span></span><br><span class="line">    <span class="built_in">window</span>.sameCount = <span class="number">3</span>; <span class="comment">//3 // weightValues数组的大小</span></span><br><span class="line">    <span class="built_in">window</span>.r1 = <span class="regexp">/\)0\s&#123;1,9&#125;(\d*)\s&#123;1,9&#125;\d\d/g</span>; <span class="comment">//使用正则表达式匹配读数</span></span><br><span class="line"></span><br><span class="line">    setRadRadioButtonList();</span><br><span class="line">    setHideOrShow();</span><br><span class="line"></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">setRadRadioButtonList</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">//if ($find("RadRadioButtonList").get_selectedIndex() === -1) &#123;</span></span><br><span class="line">    <span class="comment">//    //若未选，则选中第一次称重</span></span><br><span class="line">    <span class="comment">//    //$find("RadRadioButtonList").set_selectedIndex(0);</span></span><br><span class="line">    <span class="comment">//&#125;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">////添加切换事件</span></span><br><span class="line">    <span class="comment">//$find("RadRadioButtonList").add_selectedIndexChanged(setHideOrShow);</span></span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//判断第几次称重要显示的控件</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">setHideOrShow</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">/*const label = $("#RadLabelReadingTip")[0];*/</span></span><br><span class="line">    <span class="comment">//console.log(i.get_selectedIndex());</span></span><br><span class="line">    <span class="comment">//switch ($find("RadRadioButtonList").get_selectedIndex()) &#123;</span></span><br><span class="line">    <span class="comment">//    case 0:</span></span><br><span class="line">    <span class="comment">//        //第一次称重 毛重读数</span></span><br><span class="line">    <span class="comment">//        //label.setHTML(label.getInnerHTML().replace("皮重", "毛重"));</span></span><br><span class="line">    <span class="comment">//        $("#carNumberDiv").show();</span></span><br><span class="line">    <span class="comment">//        $("#containerDeductionDiv").show();</span></span><br><span class="line">    <span class="comment">//        $("#trayDeductionDiv").hide();</span></span><br><span class="line">    <span class="comment">//        $("#InputArea").css("background-color", "orange");</span></span><br><span class="line">    <span class="comment">//        $("#tareWeightDiv").hide();</span></span><br><span class="line">    <span class="comment">//        $("#grossWeightDiv").show();</span></span><br><span class="line">    <span class="comment">//        break;</span></span><br><span class="line">    <span class="comment">//    case 1:</span></span><br><span class="line">    <span class="comment">//        //第二次称重 皮重</span></span><br><span class="line">    <span class="comment">//        //label.setHTML(label.getInnerHTML().replace("毛重", "皮重"));</span></span><br><span class="line">    <span class="comment">//        $("#carNumberDiv").hide();</span></span><br><span class="line">    <span class="comment">//        $("#containerDeductionDiv").hide();</span></span><br><span class="line">    <span class="comment">//        $("#trayDeductionDiv").show();</span></span><br><span class="line">    <span class="comment">//        $("#InputArea").css("background-color", "lightcoral");</span></span><br><span class="line">    <span class="comment">//        $("#tareWeightDiv").show();</span></span><br><span class="line">    <span class="comment">//        $("#grossWeightDiv").hide();</span></span><br><span class="line">    <span class="comment">//        break;</span></span><br><span class="line">    <span class="comment">//    default:</span></span><br><span class="line">    <span class="comment">//        break;</span></span><br><span class="line">    <span class="comment">//&#125;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//保存</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">savePounds</span>(<span class="params">saveBtn</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(saveBtn.name);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//第几次称重</span></span><br><span class="line">    <span class="comment">//const times = $find("RadRadioButtonList").get_selectedIndex();</span></span><br><span class="line">    <span class="keyword">const</span> times = $(<span class="string">"#HiddenFieldTimes"</span>).val();</span><br><span class="line">    <span class="comment">//if (times === -1) &#123;</span></span><br><span class="line">    <span class="comment">//    //若未选，则选中第一次称重</span></span><br><span class="line">    <span class="comment">//    alertBasic("请选择第几次称重");</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">//    return false;</span></span><br><span class="line">    <span class="comment">//&#125;</span></span><br><span class="line">    <span class="comment">/*readPounds();*/</span></span><br><span class="line">    <span class="comment">//集装箱号</span></span><br><span class="line">    <span class="comment">/*const containerNumber = $find("RadTextBoxContainerNumber").get_value().trim();*/</span></span><br><span class="line">    <span class="keyword">const</span> containerNumber = (<span class="keyword">new</span> URL(<span class="built_in">window</span>.location)).searchParams.get(<span class="string">"ContainerNumber"</span>)?.trim();</span><br><span class="line">    <span class="comment">//车牌号</span></span><br><span class="line">    <span class="keyword">const</span> carNumber = $find(<span class="string">"RadTextBoxCarNumber"</span>).get_value().trim();</span><br><span class="line">    <span class="keyword">if</span> (!carNumber) &#123;</span><br><span class="line">        alertError(<span class="string">"输入有误"</span>, <span class="string">"车牌号不能为空！"</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">//if (!</span></span><br><span class="line">        <span class="comment">//    /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]&#123;1&#125;[a-zA-Z](([DF]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]&#123;4&#125;)|([0-9]&#123;5&#125;[DF]))|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]&#123;1&#125;[A-Z]&#123;1&#125;[A-Z0-9]&#123;4&#125;[A-Z0-9挂学警港澳]&#123;1&#125;)$/</span></span><br><span class="line">        <span class="comment">//        .test(carNumber)) &#123;</span></span><br><span class="line">        <span class="comment">//    alertError("输入有误", "请重新输入有效的车牌号！");</span></span><br><span class="line">        <span class="comment">//    return false;</span></span><br><span class="line">        <span class="comment">//&#125;</span></span><br><span class="line">        <span class="keyword">if</span> (carNumber.length &lt; <span class="number">3</span>) &#123;</span><br><span class="line">            alertError(<span class="string">"输入有误"</span>, <span class="string">"请重新输入有效的车牌号！"</span>);</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//集装箱扣重</span></span><br><span class="line">    <span class="keyword">const</span> containerDeduction = $find(<span class="string">"RadNumericTextBoxContainerDeduction"</span>).get_value();</span><br><span class="line">    <span class="comment">//集装箱重范围检查</span></span><br><span class="line">    <span class="keyword">if</span> (times === <span class="string">"1"</span> &amp;&amp; !containerDeduction) &#123;</span><br><span class="line">        alertError(<span class="string">"输入有误"</span>, <span class="string">"集装箱扣重不能为空！"</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">//干货箱（钢）                     门尺寸(mm)             内部尺寸(mm)     载重(Kg)                 体积(m3)</span></span><br><span class="line">        <span class="comment">//箱型     尺寸                 宽度     高度     长度     宽度     高度     最大重量 自重     最大载重 最大装载体积</span></span><br><span class="line">        <span class="comment">//20"普柜 20' x 8' x 8' 6" 2, 340 2, 274 5, 896 2, 350 2, 385 27, 000 2, 150 24, 850 33</span></span><br><span class="line">        <span class="comment">//40"普柜 40' x 8' x 8' 6" 2, 339 2, 274 12, 035 2, 350 2, 393 32, 500 3, 700 28, 800 67</span></span><br><span class="line">        <span class="comment">//40" 高柜 40' x 8' x 9' 6" 2, 340 2, 577 12, 035 2, 350 2, 697 34, 000 3, 800 30, 200 76</span></span><br><span class="line">        <span class="comment">//45" 高柜 45' x 8' x 9' 6" 2, 340 2, 585 13, 556 2, 352 2, 697 32, 500 4, 800 27, 820 86</span></span><br><span class="line">        <span class="comment">//柜型</span></span><br><span class="line">        <span class="built_in">window</span>.params = (<span class="keyword">new</span> URL(<span class="built_in">document</span>.location)).searchParams; <span class="comment">// URL接口的searchParams只读属性返回URLSearchParams对象，允许访问URL中包含的GET解码查询参数。</span></span><br><span class="line">        <span class="built_in">window</span>.containerType = params.get(<span class="string">"ContainerType"</span>);</span><br><span class="line">        <span class="keyword">switch</span> (containerType) &#123;</span><br><span class="line">            <span class="keyword">case</span> <span class="string">`20'GP`</span>:</span><br><span class="line">                <span class="keyword">if</span> (<span class="built_in">Math</span>.abs(containerDeduction - <span class="number">2150</span>) &gt;= <span class="number">1000</span>) &#123;</span><br><span class="line">                    alertError(<span class="string">"集装箱重范围检查"</span>, <span class="string">"请检查输入的集装箱扣重！"</span>);</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="string">`40'GP`</span>:</span><br><span class="line">                <span class="keyword">if</span> (<span class="built_in">Math</span>.abs(containerDeduction - <span class="number">3700</span>) &gt;= <span class="number">1000</span>) &#123;</span><br><span class="line">                    alertError(<span class="string">"集装箱重范围检查"</span>, <span class="string">"请检查输入的集装箱扣重！"</span>);</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="string">`40'HQ`</span>:</span><br><span class="line">                <span class="keyword">if</span> (<span class="built_in">Math</span>.abs(containerDeduction - <span class="number">3800</span>) &gt;= <span class="number">1000</span>) &#123;</span><br><span class="line">                    <span class="comment">// 40'HQ自重3.8吨 允许输入误差范围1000kg</span></span><br><span class="line">                    alertError(<span class="string">"集装箱重范围检查"</span>, <span class="string">"请检查输入的集装箱扣重！"</span>);</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="string">`45'HQ`</span>:</span><br><span class="line">                <span class="keyword">if</span> (<span class="built_in">Math</span>.abs(containerDeduction - <span class="number">4800</span>) &gt;= <span class="number">1000</span>) &#123;</span><br><span class="line">                    alertError(<span class="string">"集装箱重范围检查"</span>, <span class="string">"请检查输入的集装箱扣重！"</span>);</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="string">`53'HQ`</span>:</span><br><span class="line">                <span class="keyword">if</span> (<span class="built_in">Math</span>.abs(containerDeduction - <span class="number">5380</span>) &gt;= <span class="number">1000</span>) &#123;</span><br><span class="line">                    alertError(<span class="string">"集装箱重范围检查"</span>, <span class="string">"请检查输入的集装箱扣重！"</span>);</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">default</span>:</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//托盘扣重</span></span><br><span class="line">    <span class="keyword">const</span> trayDeduction = $find(<span class="string">"RadNumericTextBoxTrayDeduction"</span>).get_value();</span><br><span class="line">    <span class="keyword">if</span> (times === <span class="string">"2"</span> &amp;&amp; !trayDeduction) &#123;</span><br><span class="line">        alertError(<span class="string">"输入有误"</span>, <span class="string">"托盘扣重不能为空！"</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (!containerNumber) &#123;</span><br><span class="line">        alertError(<span class="string">"输入有误"</span>, <span class="string">"集装箱号不能为空！"</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//(async function() &#123;</span></span><br><span class="line">    <span class="comment">//    const result = await readPounds();</span></span><br><span class="line">    <span class="comment">//    return result;</span></span><br><span class="line">    <span class="comment">//&#125;)();</span></span><br><span class="line">    <span class="keyword">const</span> isSuccess = readPounds();</span><br><span class="line">    isSuccess.then(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (!<span class="built_in">Promise</span>.resolve(res)) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">//毛重读数</span></span><br><span class="line">            <span class="keyword">const</span> grossWeight = $(<span class="string">"#RadLabelGrossWeight2"</span>)[<span class="number">0</span>].innerText;</span><br><span class="line">            <span class="keyword">if</span> (times === <span class="string">"1"</span> &amp;&amp; !grossWeight) &#123;</span><br><span class="line">                alertError(<span class="string">"读数有误"</span>, <span class="string">"毛重读数不能为空！"</span>);</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//皮重读数</span></span><br><span class="line">            <span class="comment">//const tareWeight = $find("RadNumericTextBoxTareWeight").get_textBoxValue();</span></span><br><span class="line">            <span class="keyword">const</span> tareWeight = $(<span class="string">"#RadLabelTareWeight2"</span>)[<span class="number">0</span>].innerText;</span><br><span class="line">            <span class="keyword">if</span> (times === <span class="string">"2"</span> &amp;&amp; !tareWeight) &#123;</span><br><span class="line">                alertError(<span class="string">"读数有误"</span>, <span class="string">"皮重读数不能为空！"</span>);</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// TODO 异步请求：保存</span></span><br><span class="line">            <span class="comment">//window.$find("BtnSave").set_enabled(false);</span></span><br><span class="line">            $(<span class="string">`#<span class="subst">$&#123;saveBtn.name&#125;</span>`</span>)[<span class="number">0</span>].disabled = <span class="literal">false</span>;</span><br><span class="line">            $.ajax(</span><br><span class="line">                &#123;</span><br><span class="line">                    type: <span class="string">"POST"</span>,</span><br><span class="line">                    url: <span class="string">"MLWeightReadPounds.aspx/AjaxSavePounds"</span>,</span><br><span class="line">                    data: <span class="built_in">JSON</span>.stringify(&#123;</span><br><span class="line">                        containerNumber: containerNumber,</span><br><span class="line">                        times: times,</span><br><span class="line">                        grossWeight: grossWeight,</span><br><span class="line">                        tareWeight: tareWeight,</span><br><span class="line">                        value: times === <span class="string">"1"</span> ? grossWeight : tareWeight,</span><br><span class="line">                        userId: $(<span class="string">"#HiddenFieldUserId"</span>).val(),</span><br><span class="line">                        carNumber: carNumber,</span><br><span class="line">                        containerType: containerType,</span><br><span class="line">                        containerDeduction: containerDeduction,</span><br><span class="line">                        trayDeduction: trayDeduction,</span><br><span class="line">                        purchaseOrder: params.get(<span class="string">"PurchaseOrder"</span>),</span><br><span class="line">                        declarationId: params.get(<span class="string">"DeclarationId"</span>)</span><br><span class="line">                    &#125;),</span><br><span class="line">                    dataType: <span class="string">"json"</span>,</span><br><span class="line">                    <span class="comment">// async: false,</span></span><br><span class="line">                    contentType: <span class="string">"application/json; charset=utf-8"</span>,</span><br><span class="line">                    success: <span class="function"><span class="keyword">function</span> (<span class="params">infos</span>) </span>&#123;</span><br><span class="line">                        <span class="keyword">const</span> jsonRes = <span class="built_in">JSON</span>.parse(infos.d);</span><br><span class="line">                        <span class="built_in">console</span>.log(jsonRes);</span><br><span class="line">                        <span class="keyword">if</span> (jsonRes.status === <span class="string">"200"</span>) &#123;</span><br><span class="line">                            alertSuccess(<span class="string">"保存成功！"</span>);</span><br><span class="line">                        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                            <span class="comment">//alert(infos.d.errMsg);</span></span><br><span class="line">                            <span class="built_in">console</span>.log(jsonRes);</span><br><span class="line">                            alertError(jsonRes.errMsg, jsonRes.exception);</span><br><span class="line">                        &#125;</span><br><span class="line"></span><br><span class="line">                        <span class="built_in">window</span>.location.reload();</span><br><span class="line">                        <span class="comment">//window.$find("BtnSave").set_enabled(true);</span></span><br><span class="line">                        $(<span class="string">`#<span class="subst">$&#123;saveBtn.name&#125;</span>`</span>)[<span class="number">0</span>].disabled = <span class="literal">false</span>;</span><br><span class="line">                    &#125;,</span><br><span class="line">                    error: <span class="function"><span class="keyword">function</span> (<span class="params">exception</span>) </span>&#123;</span><br><span class="line">                        alertError(<span class="string">"浏览器Ajax请求错误"</span>, exception.responseText);</span><br><span class="line">                        <span class="comment">//window.$find("BtnSave").set_enabled(true);</span></span><br><span class="line">                        $(<span class="string">`#<span class="subst">$&#123;saveBtn.name&#125;</span>`</span>)[<span class="number">0</span>].disabled = <span class="literal">false</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;);</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 临时保存读数至会话存储</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">savePoundsToLocalStorage</span>(<span class="params">weightValue</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">const</span> userId = $(<span class="string">"#HiddenFieldUserId"</span>)[<span class="number">0</span>].value; <span class="comment">// 工号</span></span><br><span class="line">    <span class="keyword">const</span> containerId = $(<span class="string">"#HiddenFieldContainerId"</span>)[<span class="number">0</span>].value; <span class="comment">// 集装箱Id</span></span><br><span class="line">    <span class="comment">//第几次称重</span></span><br><span class="line">    <span class="comment">//const times = $find("RadRadioButtonList").get_selectedIndex();</span></span><br><span class="line">    <span class="keyword">const</span> times = $(<span class="string">"#HiddenFieldTimes"</span>).val();</span><br><span class="line">    sessionStorage.setItem(<span class="string">"ML_WEIGHT_USERID"</span>, userId);</span><br><span class="line">    sessionStorage.setItem(<span class="string">"ML_WEIGHT_CONTAINER_ID"</span>, containerId);</span><br><span class="line">    sessionStorage.setItem(<span class="string">`ML_WEIGHT_VALUE_<span class="subst">$&#123;times&#125;</span>`</span>, weightValue);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">function</span> <span class="title">readPounds</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 判断是否支持Web串行API。</span></span><br><span class="line">    <span class="keyword">if</span> (!(<span class="string">"serial"</span> <span class="keyword">in</span> navigator)) &#123;</span><br><span class="line">        alertError(<span class="string">"Web串行接口无法使用"</span>, <span class="string">"该浏览器不支持读取串口设备，请更换Chrome浏览器！"</span>);</span><br><span class="line">        <span class="comment">//alert("该浏览器不支持读取串口设备，请更换Chrome浏览器！");</span></span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">// 获取用户之前授予网站访问权限的所有串行端口。</span></span><br><span class="line">        <span class="keyword">const</span> ports = <span class="keyword">await</span> navigator.serial.getPorts();</span><br><span class="line"></span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">`已授权的串行端口：<span class="subst">$&#123;ports.length&#125;</span> 个`</span>);</span><br><span class="line">        ports.forEach(<span class="function"><span class="params">p</span> =&gt;</span> <span class="built_in">console</span>.log(p));</span><br><span class="line"></span><br><span class="line">        <span class="keyword">let</span> port;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// TODO 闫伟明 串行端口选错连接不上异常处理；串行端口选择过滤</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (ports.length === <span class="number">1</span>) &#123;</span><br><span class="line">            port = ports[<span class="number">0</span>];</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">"选择第一个端口打开"</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">"请选择一个端口打开"</span>);</span><br><span class="line">            <span class="comment">// 提示用户选择任意串口。</span></span><br><span class="line">            port = <span class="keyword">await</span> navigator.serial.requestPort();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">// 等待串口打开。</span></span><br><span class="line">            <span class="keyword">await</span> port.open(&#123;</span><br><span class="line">                baudRate: <span class="number">9600</span>,<span class="comment">/*建立串行通信的波特率*/</span></span><br><span class="line">                dataBits: <span class="number">8</span>,<span class="comment">/*每帧的数据位数*/</span></span><br><span class="line">                stopBits: <span class="number">1</span>,<span class="comment">/*帧末尾的停止位数*/</span></span><br><span class="line">                parity: <span class="string">"even"</span>,<span class="comment">/*奇偶校验模式*/</span></span><br><span class="line">                bufferSize: <span class="number">255</span>,<span class="comment">/*缓冲区大小*/</span></span><br><span class="line">                flowControl: <span class="string">"none"</span><span class="comment">/*流量控制模式*/</span></span><br><span class="line">            &#125;);</span><br><span class="line"></span><br><span class="line">        &#125; <span class="keyword">catch</span> (e) &#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">`等待串口打开中...<span class="subst">$&#123;e&#125;</span>`</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">"端口打开成功！"</span>);</span><br><span class="line"></span><br><span class="line">        toast(<span class="string">"打开串口"</span>, <span class="string">`<span class="subst">$&#123;port&#125;</span>端口打开成功！`</span>);</span><br><span class="line"></span><br><span class="line">        <span class="built_in">window</span>.weightValues = []; <span class="comment">//存储最近三次称重值</span></span><br><span class="line">        <span class="comment">//window.sameCount = 10; //3 // weightValues数组的大小</span></span><br><span class="line">        <span class="comment">//window.r1 = /\)0\s&#123;5&#125;(\d*)\s&#123;5&#125;00/g; //使用正则表达式匹配读数</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">let</span> s = <span class="keyword">new</span> <span class="built_in">String</span>(); <span class="comment">// 储存地磅串行接口传来的数据 一个完整的数据是十六进制字符串</span></span><br><span class="line">        <span class="keyword">while</span> (port.readable) &#123;</span><br><span class="line">            <span class="keyword">const</span> reader = port.readable.getReader();</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">`获取到串行输出流：<span class="subst">$&#123;reader&#125;</span>`</span>);</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                <span class="built_in">console</span>.log(<span class="string">"开始监听串行流..."</span>);</span><br><span class="line">                <span class="comment">// 监听来自串行设备的数据。</span></span><br><span class="line">                outerWhileLoop: <span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line">                    <span class="built_in">console</span>.log(<span class="string">"正等待读取串行输出流..."</span>);</span><br><span class="line">                    <span class="keyword">const</span> &#123; value, done &#125; = <span class="keyword">await</span> reader.read();</span><br><span class="line">                    <span class="built_in">console</span>.log(<span class="string">"读取串行输出流..."</span>);</span><br><span class="line">                    <span class="keyword">if</span> (done) &#123;</span><br><span class="line">                        <span class="comment">// 允许稍后关闭串口。</span></span><br><span class="line">                        reader.releaseLock();</span><br><span class="line">                        <span class="keyword">break</span>;</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="comment">// 值是一个 Uint8Array.</span></span><br><span class="line">                    <span class="built_in">console</span>.log(<span class="string">`接收数据 Uint8Array 中...<span class="subst">$&#123;value&#125;</span>`</span>);</span><br><span class="line">                    <span class="built_in">console</span>.log(<span class="string">`转换数据 Uint8ArrayToString 中...<span class="subst">$&#123;Uint8ArrayToString(value)&#125;</span>`</span>);</span><br><span class="line">                    <span class="built_in">console</span>.log(s);</span><br><span class="line">                    s += Uint8ArrayToString(value);</span><br><span class="line">                    <span class="keyword">if</span> (s.length &lt; <span class="number">200</span>) &#123;</span><br><span class="line">                        <span class="built_in">console</span>.log(<span class="string">"累计收到字符串长度小于200，继续读取..."</span>);</span><br><span class="line">                        <span class="keyword">continue</span>;</span><br><span class="line">                    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (s.length &gt; <span class="number">10000</span>) &#123;</span><br><span class="line">                        s = <span class="string">""</span>;</span><br><span class="line">                        <span class="built_in">console</span>.log(<span class="string">"累计收到字符串长度大于10000，清空..."</span>);</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="comment">// 2022年12月16日13:32:54 新数据格式解析 -- START</span></span><br><span class="line">                    <span class="built_in">console</span>.log(<span class="string">`使用 <span class="subst">$&#123;r1&#125;</span> 进行正则匹配...`</span>);</span><br><span class="line">                    <span class="keyword">while</span> (r1.exec(s)) &#123;</span><br><span class="line">                        <span class="keyword">const</span> curWeight = <span class="built_in">RegExp</span>.$<span class="number">1</span>;</span><br><span class="line">                        <span class="built_in">console</span>.log(curWeight + <span class="string">" "</span> + <span class="keyword">new</span> <span class="built_in">Date</span>());</span><br><span class="line">                        <span class="built_in">window</span>.showWeight(curWeight);</span><br><span class="line">                        <span class="comment">// 取值3次，3次相等即为结果</span></span><br><span class="line">                        <span class="keyword">if</span> (weightValues.length &lt; sameCount) &#123;</span><br><span class="line">                            <span class="comment">//称重值小于3个，入队</span></span><br><span class="line">                            weightValues.push(curWeight);</span><br><span class="line">                        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                            <span class="comment">//称重值3个，先出队再入队</span></span><br><span class="line">                            weightValues.shift();</span><br><span class="line">                            weightValues.push(curWeight);</span><br><span class="line">                        &#125;</span><br><span class="line">                        <span class="built_in">console</span>.log(<span class="string">`weightValues:<span class="subst">$&#123;weightValues&#125;</span>`</span>);</span><br><span class="line"></span><br><span class="line">                        <span class="keyword">if</span> (weightValues.length === sameCount) &#123;</span><br><span class="line">                            <span class="comment">//判断最近三次值是否相等</span></span><br><span class="line">                            <span class="keyword">const</span> elementsAreEqual = weightValues.every(<span class="function"><span class="params">weightValue</span> =&gt;</span> weightValue === weightValues[<span class="number">0</span>]);</span><br><span class="line">                            <span class="keyword">if</span> (elementsAreEqual) &#123;</span><br><span class="line">                                <span class="comment">//三次值相等 确定称重结果</span></span><br><span class="line">                                <span class="comment">//console.log(`weightValues:$&#123;weightValues&#125;`);</span></span><br><span class="line">                                <span class="built_in">console</span>.log(<span class="string">`weightValues[0]:<span class="subst">$&#123;weightValues[<span class="number">0</span>]&#125;</span>`</span>);</span><br><span class="line">                                <span class="comment">//window.setWeight(weightValues[0]);</span></span><br><span class="line">                                <span class="keyword">const</span> times = $(<span class="string">"#HiddenFieldTimes"</span>).val();</span><br><span class="line">                                <span class="keyword">switch</span> (times) &#123;</span><br><span class="line">                                    <span class="keyword">case</span> <span class="string">"1"</span>:</span><br><span class="line">                                        <span class="comment">//第一次称重 毛重读数</span></span><br><span class="line">                                        <span class="comment">//$("#RadNumericTextBoxGrossWeight").val(weightValues[0]);</span></span><br><span class="line">                                        $(<span class="string">"#RadLabelGrossWeight2"</span>)[<span class="number">0</span>].innerText = weightValues[<span class="number">0</span>];</span><br><span class="line">                                        <span class="keyword">break</span>;</span><br><span class="line">                                    <span class="keyword">case</span> <span class="string">"2"</span>:</span><br><span class="line">                                        <span class="comment">//第二次称重 皮重</span></span><br><span class="line">                                        <span class="comment">//$("#RadNumericTextBoxTareWeight").val(weightValues[0]);</span></span><br><span class="line">                                        $(<span class="string">"#RadLabelTareWeight2"</span>)[<span class="number">0</span>].innerText = weightValues[<span class="number">0</span>];</span><br><span class="line"></span><br><span class="line">                                        <span class="keyword">break</span>;</span><br><span class="line">                                    <span class="keyword">default</span>:</span><br><span class="line">                                        <span class="keyword">break</span>;</span><br><span class="line">                                &#125;</span><br><span class="line">                                toast(<span class="string">`读数成功：<span class="subst">$&#123;weightValues[<span class="number">0</span>]&#125;</span>`</span>);</span><br><span class="line"></span><br><span class="line">                                <span class="comment">// 存储至localstorage</span></span><br><span class="line">                                <span class="comment">//savePoundsToLocalStorage(weightValues[0]);</span></span><br><span class="line"></span><br><span class="line">                                <span class="comment">// 清空接收到的数据，准备下次读取</span></span><br><span class="line">                                s = <span class="string">""</span>;</span><br><span class="line"></span><br><span class="line">                                <span class="comment">//若要停止读数</span></span><br><span class="line">                                <span class="comment">//允许稍后关闭串口。</span></span><br><span class="line">                                <span class="built_in">console</span>.log(<span class="string">"releasing Lock"</span>);</span><br><span class="line">                                reader.releaseLock();</span><br><span class="line">                                <span class="comment">//关闭串口</span></span><br><span class="line">                                <span class="keyword">await</span> port.close();</span><br><span class="line">                                <span class="comment">//跳出监听循环，退出读磅函数</span></span><br><span class="line">                                <span class="built_in">console</span>.log(<span class="string">"已经关闭串口"</span>);</span><br><span class="line">                                <span class="keyword">break</span> outerWhileLoop;</span><br><span class="line">                            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                                <span class="comment">//三次值不等 继续</span></span><br><span class="line">                                <span class="comment">//console.log(`weightValues:$&#123;weightValues&#125;`);</span></span><br><span class="line">                                <span class="built_in">console</span>.log(<span class="string">"weightMsg三次值不相等"</span>);</span><br><span class="line">                            &#125;</span><br><span class="line"></span><br><span class="line">                        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (weightValues.length &gt; sameCount) &#123;</span><br><span class="line">                            <span class="built_in">console</span>.error(<span class="string">"执行错误，队列溢出"</span>);</span><br><span class="line">                            <span class="built_in">window</span>.weightValues = [];</span><br><span class="line">                            <span class="built_in">console</span>.error(<span class="string">"已重置队列为空"</span>);</span><br><span class="line">                        &#125;</span><br><span class="line"></span><br><span class="line">                        <span class="comment">// 实时显示本次称重值</span></span><br><span class="line">                        <span class="comment">// 因为$("#&lt;%=ReadingPounds.ClientID %&gt;").text(`$&#123;weightMsg&#125;`);只能在aspx文件中，放在独立js文件中无法正确编译，故抽取成方法，使用windows对象调用。</span></span><br><span class="line">                        <span class="built_in">window</span>.showWeight(weightValues[<span class="number">0</span>]);</span><br><span class="line"></span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="comment">// -- END 新数据格式解析</span></span><br><span class="line"></span><br><span class="line">                    <span class="comment">// START T800数据帧解析</span></span><br><span class="line">                    <span class="comment">/*//s1储存地磅传来一个完整数据帧的数据部分，应是15个字节</span></span><br><span class="line"><span class="comment">                    const s1 = s.substring(s.lastIndexOf("02") + 2, s.lastIndexOf("0D"));</span></span><br><span class="line"><span class="comment">                    if (s1.length === 30) &#123;</span></span><br><span class="line"><span class="comment">                        //转换过程：十六进制字符串-- &gt; 十进制int数-- &gt; 二进制表示字符串</span></span><br><span class="line"><span class="comment">                        const dec = parseInt(s1.substring(0, 2), 16).toString(2);</span></span><br><span class="line"><span class="comment">                        //状态字A部分</span></span><br><span class="line"><span class="comment">                        console.log(dec);</span></span><br><span class="line"><span class="comment">                        //状态字A的Bits 0,1,2 小数点位</span></span><br><span class="line"><span class="comment">                        const flag = dec.substring(dec.length - 3);</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                        // 用于确定小数点位置</span></span><br><span class="line"><span class="comment">                        let flag2 = "";</span></span><br><span class="line"><span class="comment">                        for (let k = flag.length - 1; k &gt;= 0; k--) &#123;</span></span><br><span class="line"><span class="comment">                            flag2 += flag[k];</span></span><br><span class="line"><span class="comment">                        &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                        //显示重量、毛重或者净重</span></span><br><span class="line"><span class="comment">                        //共6个字节，表示6位不带符号不带小数点的数字</span></span><br><span class="line"><span class="comment">                        //转换过程：十六进制字符串 --&gt; 十进制整数int（Unicode值） --&gt; 数字（ascii字符）</span></span><br><span class="line"><span class="comment">                        const ss = s1.substring(6, 18);</span></span><br><span class="line"><span class="comment">                        console.log(`ss:$&#123;ss&#125;`);</span></span><br><span class="line"><span class="comment">                        // 临时存储最终结果的6位数字</span></span><br><span class="line"><span class="comment">                        let buffer = "";</span></span><br><span class="line"><span class="comment">                        for (let i = 0; i &lt; ss.length; i += 2) &#123;</span></span><br><span class="line"><span class="comment">                            console.log(`十六进制字符串 --&gt; 十进制整数int（Unicode值）：$&#123;ss.substring(i, i + 2)&#125; --&gt; $&#123;parseInt(ss.substring(i, i + 2), 16)&#125;`);</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                            //先十六进制字符串 --&gt; 十进制整数int（Unicode值），再将 Unicode 值转换为字符:</span></span><br><span class="line"><span class="comment">                            buffer += String.fromCharCode(parseInt(ss.substring(i, i + 2), 16));</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                            console.log(`buffer:$&#123;buffer&#125;`);</span></span><br><span class="line"><span class="comment">                        &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                        console.log(`buffer 临时存储最终结果的6位数字:$&#123;buffer&#125;`);</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                        let weightMsg = "";</span></span><br><span class="line"><span class="comment">                        // 判断小数点的位置</span></span><br><span class="line"><span class="comment">                        switch (flag) &#123;</span></span><br><span class="line"><span class="comment">                            case "111":</span></span><br><span class="line"><span class="comment">                                weightMsg = `$&#123;buffer.substring(0, 1)&#125;.$&#123;buffer.substring(1, 6)&#125;`;</span></span><br><span class="line"><span class="comment">                                break;</span></span><br><span class="line"><span class="comment">                            case "011":</span></span><br><span class="line"><span class="comment">                                weightMsg = `$&#123;buffer.substring(0, 2)&#125;.$&#123;buffer.substring(2, 6)&#125;`;</span></span><br><span class="line"><span class="comment">                                break;</span></span><br><span class="line"><span class="comment">                            case "101":</span></span><br><span class="line"><span class="comment">                                weightMsg = `$&#123;buffer.substring(0, 3)&#125;.$&#123;buffer.substring(3, 6)&#125;`;</span></span><br><span class="line"><span class="comment">                                break;</span></span><br><span class="line"><span class="comment">                            case "001":</span></span><br><span class="line"><span class="comment">                                weightMsg = `$&#123;buffer.substring(0, 4)&#125;.$&#123;buffer.substring(4, 6)&#125;`;</span></span><br><span class="line"><span class="comment">                                break;</span></span><br><span class="line"><span class="comment">                            case "110":</span></span><br><span class="line"><span class="comment">                                weightMsg = `$&#123;buffer.substring(0, 5)&#125;.$&#123;buffer.substring(5, 6)&#125;`;</span></span><br><span class="line"><span class="comment">                                break;</span></span><br><span class="line"><span class="comment">                            case "010":</span></span><br><span class="line"><span class="comment">                                weightMsg = `$&#123;buffer.substring(0, 6)&#125;`;</span></span><br><span class="line"><span class="comment">                                break;</span></span><br><span class="line"><span class="comment">                            case "100":</span></span><br><span class="line"><span class="comment">                                weightMsg = `$&#123;buffer.substring(1, 6)&#125;0`;</span></span><br><span class="line"><span class="comment">                                break;</span></span><br><span class="line"><span class="comment">                            case "000":</span></span><br><span class="line"><span class="comment">                                weightMsg = `$&#123;buffer.substring(2, 6)&#125;00`;</span></span><br><span class="line"><span class="comment">                                break;</span></span><br><span class="line"><span class="comment">                        &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                        // 取值3次，3次相等即为结果</span></span><br><span class="line"><span class="comment">                        if (weightValues.length &lt; 3) &#123;</span></span><br><span class="line"><span class="comment">                            //称重值小于3个，入队</span></span><br><span class="line"><span class="comment">                            weightValues.push(weightMsg);</span></span><br><span class="line"><span class="comment">                        &#125; else &#123;</span></span><br><span class="line"><span class="comment">                            //称重值3个，先出队再入队</span></span><br><span class="line"><span class="comment">                            weightValues.shift();</span></span><br><span class="line"><span class="comment">                            weightValues.push(weightMsg);</span></span><br><span class="line"><span class="comment">                        &#125;</span></span><br><span class="line"><span class="comment">                        console.log(`weightValues:$&#123;weightValues&#125;`);</span></span><br><span class="line"><span class="comment">                        </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                        if (weightValues.length === 3) &#123;</span></span><br><span class="line"><span class="comment">                            //判断最近三次值是否相等</span></span><br><span class="line"><span class="comment">                            const elementsAreEqual = weightValues.every(weightValue =&gt; weightValue === weightValues[0]);</span></span><br><span class="line"><span class="comment">                            if (elementsAreEqual) &#123;</span></span><br><span class="line"><span class="comment">                                //三次值相等 确定称重结果</span></span><br><span class="line"><span class="comment">                                //console.log(`weightValues:$&#123;weightValues&#125;`);</span></span><br><span class="line"><span class="comment">                                console.log(`weightValues[0]:$&#123;weightValues[0]&#125;`);</span></span><br><span class="line"><span class="comment">                                alert("读数成功！");</span></span><br><span class="line"><span class="comment">                                window.setWeight(weightValues[0]);</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                                // 存储至localstorage</span></span><br><span class="line"><span class="comment">                                //savePoundsToLocalStorage(weightValues[0]);</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                                //若要停止读数</span></span><br><span class="line"><span class="comment">                                //允许稍后关闭串口。</span></span><br><span class="line"><span class="comment">                                console.log("releasing Lock");</span></span><br><span class="line"><span class="comment">                                reader.releaseLock();</span></span><br><span class="line"><span class="comment">                                //关闭串口</span></span><br><span class="line"><span class="comment">                                await port.close();</span></span><br><span class="line"><span class="comment">                                //跳出监听循环，退出读磅函数</span></span><br><span class="line"><span class="comment">                                console.log("已经关闭串口");</span></span><br><span class="line"><span class="comment">                                break;</span></span><br><span class="line"><span class="comment">                            &#125; else &#123;</span></span><br><span class="line"><span class="comment">                                //三次值不等 继续</span></span><br><span class="line"><span class="comment">                                //console.log(`weightValues:$&#123;weightValues&#125;`);</span></span><br><span class="line"><span class="comment">                                console.log("weightMsg三次值不相等");</span></span><br><span class="line"><span class="comment">                            &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                        &#125; else if (weightValues.length &gt; 3) &#123;</span></span><br><span class="line"><span class="comment">                            alert("执行错误，队列溢出");</span></span><br><span class="line"><span class="comment">                        &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                        // 实时显示本次称重值</span></span><br><span class="line"><span class="comment">                        // 因为$("#&lt;%=ReadingPounds.ClientID %&gt;").text(`$&#123;weightMsg&#125;`);只能在aspx文件中，放在独立js文件中无法正确编译，故抽取成方法，使用windows对象调用。</span></span><br><span class="line"><span class="comment">                        window.showWeight(weightValues[0]);</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                        // 清空接收到的数据，准备下次读取</span></span><br><span class="line"><span class="comment">                        s = "";</span></span><br><span class="line"><span class="comment">                    &#125;*/</span></span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">            &#125; <span class="keyword">catch</span> (error) &#123;</span><br><span class="line">                <span class="built_in">console</span>.error(error);</span><br><span class="line">                alertError(<span class="string">"监听串行流输出遇到错误"</span>, error);</span><br><span class="line">            &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">                reader.releaseLock();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 获取用户之前授予网站访问权限的所有串行端口。</span></span><br><span class="line">        <span class="comment">//const ports = await navigator.serial.getPorts();</span></span><br><span class="line">        <span class="comment">//alert(ports);</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Uint8ArrayToString</span>(<span class="params">fileData</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> dataString = <span class="string">""</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; fileData.length; i++) &#123;</span><br><span class="line">        dataString += <span class="built_in">String</span>.fromCharCode(fileData[i]);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> dataString;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 检查浏览器版本</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">checkBrowserVersion</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">const</span> browserName = getBrowserName(navigator.userAgent);</span><br><span class="line">    <span class="keyword">const</span> protocol = <span class="built_in">window</span>.location.protocol;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">`You are using: <span class="subst">$&#123;browserName&#125;</span> over <span class="subst">$&#123;protocol&#125;</span> protocol.`</span>);</span><br><span class="line">    <span class="keyword">if</span> (!(<span class="string">"serial"</span> <span class="keyword">in</span> navigator)) &#123;</span><br><span class="line">        alertError(<span class="string">"无法使用"</span>, <span class="string">"请更换Chrome或Edge浏览器访问此页面（该浏览器不支持读取串口设备）！"</span>);</span><br><span class="line">        <span class="comment">//$("body").html(`&lt;div class="container"&gt;&lt;h1&gt;$&#123;`You are using: $&#123;browserName&#125; over $&#123;protocol&#125;// protocol.`</span></span><br><span class="line">        <span class="comment">//    &#125;&lt;/h1&gt;&lt;hr/&gt;&lt;h2&gt;检测到该浏览器不支持读取串口设备！&lt;/h2&gt;&lt;h3&gt;Please change your Chrome or Edge browser to visit this page (as this browser does not support accessing and reading serial port devices)!&lt;/h3&gt;&lt;/div&gt;`);</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getBrowserName</span>(<span class="params">userAgent</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// The order matters here, and this may report false positives for unlisted browsers.</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (userAgent.includes(<span class="string">"Firefox"</span>)) &#123;</span><br><span class="line">        <span class="comment">// "Mozilla/5.0 (X11; Linux i686; rv:104.0) Gecko/20100101 Firefox/104.0"</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Mozilla Firefox"</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (userAgent.includes(<span class="string">"SamsungBrowser"</span>)) &#123;</span><br><span class="line">        <span class="comment">// "Mozilla/5.0 (Linux; Android 9; SAMSUNG SM-G955F Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/9.4 Chrome/67.0.3396.87 Mobile Safari/537.36"</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Samsung Internet"</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (userAgent.includes(<span class="string">"Opera"</span>) || userAgent.includes(<span class="string">"OPR"</span>)) &#123;</span><br><span class="line">        <span class="comment">// "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_5_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36 OPR/90.0.4480.54"</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Opera"</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (userAgent.includes(<span class="string">"Trident"</span>)) &#123;</span><br><span class="line">        <span class="comment">// "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)"</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Microsoft Internet Explorer"</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (userAgent.includes(<span class="string">"Edge"</span>)) &#123;</span><br><span class="line">        <span class="comment">// "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Microsoft Edge (Legacy)"</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (userAgent.includes(<span class="string">"Edg"</span>)) &#123;</span><br><span class="line">        <span class="comment">// "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36 Edg/104.0.1293.70"</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Microsoft Edge (Chromium)"</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (userAgent.includes(<span class="string">"Chrome"</span>)) &#123;</span><br><span class="line">        <span class="comment">// "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Google Chrome or Chromium"</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (userAgent.includes(<span class="string">"Safari"</span>)) &#123;</span><br><span class="line">        <span class="comment">// "Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6 Mobile/15E148 Safari/604.1"</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Apple Safari"</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"unknown"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// my弹窗封装</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">alertPro</span>(<span class="params">type, title, text</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">window</span>.Swal.fire(&#123;</span><br><span class="line">        icon: type,</span><br><span class="line">        title: title,</span><br><span class="line">        text: text<span class="comment">//,</span></span><br><span class="line">        <span class="comment">//footer: '&lt;a href=""&gt;测试弹窗&lt;/a&gt;'</span></span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 错误弹窗提示</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">alertError</span>(<span class="params">title, text</span>) </span>&#123;</span><br><span class="line">    alertPro(<span class="string">"error"</span>, title, text);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 简单弹窗提示</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">alertBasic</span>(<span class="params">text</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">window</span>.Swal.fire(text);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 成功弹窗提示</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">alertSuccess</span>(<span class="params">title, text</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">window</span>.Swal.fire(</span><br><span class="line">        title,</span><br><span class="line">        text,</span><br><span class="line">        <span class="string">"success"</span></span><br><span class="line">    );</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Toast</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">toast</span>(<span class="params">text</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">window</span>.Swal.mixin(&#123;</span><br><span class="line">        toast: <span class="literal">true</span>,</span><br><span class="line">        position: <span class="string">"top-end"</span>,</span><br><span class="line">        showConfirmButton: <span class="literal">false</span>,</span><br><span class="line">        timer: <span class="number">3000</span>,</span><br><span class="line">        timerProgressBar: <span class="literal">true</span>,</span><br><span class="line">        didOpen: <span class="function">(<span class="params">toast</span>) =&gt;</span> &#123;</span><br><span class="line">            toast.addEventListener(<span class="string">"mouseenter"</span>, <span class="built_in">window</span>.Swal.stopTimer);</span><br><span class="line">            toast.addEventListener(<span class="string">"mouseleave"</span>, <span class="built_in">window</span>.Swal.resumeTimer);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;).fire(&#123;</span><br><span class="line">        icon: <span class="string">"success"</span>,</span><br><span class="line">        title: text</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>

<h2 id="chrome浏览器配置在http协议使用web串行api"><a href="#chrome浏览器配置在http协议使用web串行api" class="headerlink" title="chrome浏览器配置在http协议使用web串行api"></a>chrome浏览器配置在http协议使用web串行api</h2><p>Web串行Api需要域是HTTPS协议的，否则该api被Chrome屏蔽，无法被调用。仅在本地localhost调试开发时可以使用http域，Chrome浏览器会暴露该api。</p>
<p>可以通过配置Chrome浏览器解除这个限制，需要配置两个地方：</p>
<ol>
<li>打开<code>chrome://flags/</code>，设置<code>Insecure origins treated as secure</code>为<code>Enabeld</code>，填入要配置的域名<code>http://192.168.80.53:9000</code><br><img src="/2022/11/18/JavaScript%E4%BD%BF%E7%94%A8-Web-Serial-API%E8%8E%B7%E5%8F%96%E4%B8%B2%E8%A1%8C%E8%AE%BE%E5%A4%87%E7%AB%AF%E5%8F%A3%E6%95%B0%E6%8D%AE-%E5%9C%B0%E7%A3%85%E4%B8%B2%E5%8F%A3%E6%95%B0%E6%8D%AE/2023-02-08-10-58-04.png" alt="配置chrome://flags/"><ul>
<li>Enable Bluetooth Serial Port Profile in Serial API为开启蓝牙设备串行api。</li>
</ul>
</li>
<li>在桌面<code>Google Chrome</code>图标的快捷方式上，鼠标右键点<code>属性</code>，修改<code>目标</code>字段加上启动参数，修改后为<code>&quot;C:\Program Files\Google\Chrome\Application\chrome.exe&quot; --unsafely-treat-insecure-origin-as-secure=&quot;http://192.168.80.53:9000&quot;</code><br><img src="/2022/11/18/JavaScript%E4%BD%BF%E7%94%A8-Web-Serial-API%E8%8E%B7%E5%8F%96%E4%B8%B2%E8%A1%8C%E8%AE%BE%E5%A4%87%E7%AB%AF%E5%8F%A3%E6%95%B0%E6%8D%AE-%E5%9C%B0%E7%A3%85%E4%B8%B2%E5%8F%A3%E6%95%B0%E6%8D%AE/2023-02-08-10-59-40.png" alt="快捷方式——目标添加启动参数"></li>
</ol>

          
      
    </div>
    
    
      <footer class="article-footer">
        完
      </footer>
    
  </div>
  
    
<nav id="article-nav">
  <div class="article-nav-block">
    
      <a href="../../../../2023/01/14/AutoReconnectWiFi/" id="article-nav-newer" class="article-nav-link-wrap">
        <strong class="article-nav-caption"></strong>
        <div class="article-nav-title">
          
            检测断网自动重连WiFi脚本
          
        </div>
      </a>
    
  </div>
  <div class="article-nav-block">
    
      <a href="../../../09/07/JavaScript%E4%B9%8B%E5%87%BD%E6%95%B0/" id="article-nav-older" class="article-nav-link-wrap">
        <div class="article-nav-title">JavaScript 之函数</div>
        <strong class="article-nav-caption"></strong>
      </a>
    
  </div>
</nav>

    <!-- <link rel="stylesheet" href="/css/gitment.css">  -->
<script src='//unpkg.com/valine/dist/Valine.min.js'></script>

<div id="vcommentsContainer"></div>
<!--引用评论框输入特效js文件-->

<script src="../../../../js/shuru.js"></script>

<script>
  POWERMODE.colorful = true; // make power mode colorful
  POWERMODE.shake = true; // turn off shake
  document.body.addEventListener('input', POWERMODE);
</script>
<!-- valine评论系统 -->
<script>
  new Valine({
      el: '#vcommentsContainer',
      appId: 'AttjBiS7UwxkxjV1CSrNywoi-gzGzoHsz',
      appKey: 'F50aWycFFmAPLC8CfSW7rXdP',
      avatar: 'monsterid',
      enableQQ: true,
      placeholder: '昵称处填QQ号自动抓取网名和邮箱哟~'
  })
</script>


    <!-- <link rel="stylesheet" href="/css/gitment.css"> 
<script src="/js/gitment.js"></script>

<div id="gitmentContainer"></div>

<script>
var gitment = new Gitment({
  owner: '',
  repo: '',
  oauth: {
    client_id: '',
    client_secret: '',
  },
})
gitment.render('gitmentContainer')
</script>

 -->

  
  
</article>
</section>
        <aside id="sidebar">
  
    <div class="widget-box">
  <div class="avatar-box">
    <img class="avatar" src="https://q1.qlogo.cn/g?b=qq&amp;nk=979727728&amp;s=640" title="图片来自QQ"></img>
    <h3 class="avatar-name">
      
        许嵩老公
      
    </h3>
    <p class="avatar-slogan">
      深吸一口梦，吹个气球存起来。
    </p>
  </div>
</div>


  
    

  
    
  <div class="widget-box">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/NET/" rel="tag">.NET</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Cookie/" rel="tag">Cookie</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ES6/" rel="tag">ES6</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Git-Bash/" rel="tag">Git Bash</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Github/" rel="tag">Github</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Github-Actions/" rel="tag">Github Actions</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/HDFS/" rel="tag">HDFS</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/HTTP/" rel="tag">HTTP</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Hadoop/" rel="tag">Hadoop</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Hexo/" rel="tag">Hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Idea/" rel="tag">Idea</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/JVM/" rel="tag">JVM</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Java/" rel="tag">Java</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/JavaScript/" rel="tag">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Linux/" rel="tag">Linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/MapReduce/" rel="tag">MapReduce</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Markdown/" rel="tag">Markdown</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Maven/" rel="tag">Maven</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Node/" rel="tag">Node</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Node-js/" rel="tag">Node.js</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/SQL/" rel="tag">SQL</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Serial-Port/" rel="tag">Serial Port</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Shell/" rel="tag">Shell</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/SpringBoot/" rel="tag">SpringBoot</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/TCP/" rel="tag">TCP</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/VSCode/" rel="tag">VSCode</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Vue/" rel="tag">Vue</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/WebSocket/" rel="tag">WebSocket</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/YARN/" rel="tag">YARN</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/hexo/" rel="tag">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/macOS/" rel="tag">macOS</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ssh/" rel="tag">ssh</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E4%B8%AD%E6%96%87%E4%B9%B1%E7%A0%81/" rel="tag">中文乱码</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%A4%A7%E6%95%B0%E6%8D%AE/" rel="tag">大数据</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/" rel="tag">安装教程</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%AF%86%E9%92%A5/" rel="tag">密钥</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%B9%B6%E8%A1%8C%E7%BC%96%E7%A8%8B/" rel="tag">并行编程</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E6%95%B0%E6%8D%AE%E5%BA%93/" rel="tag">数据库</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%94%B5%E8%84%91/" rel="tag">电脑</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%AB%B9%E4%BA%91/" rel="tag">竹云</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%BB%88%E7%AB%AF/" rel="tag">终端</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E8%84%9A%E6%9C%AC/" rel="tag">脚本</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E8%BD%AC%E8%BD%BD/" rel="tag">转载</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E8%BD%AF%E4%BB%B6/" rel="tag">软件</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-box">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="../../../../tags/NET/" style="font-size: 10px;">.NET</a> <a href="../../../../tags/Cookie/" style="font-size: 10px;">Cookie</a> <a href="../../../../tags/ES6/" style="font-size: 10px;">ES6</a> <a href="../../../../tags/Git-Bash/" style="font-size: 11.67px;">Git Bash</a> <a href="../../../../tags/Github/" style="font-size: 13.33px;">Github</a> <a href="../../../../tags/Github-Actions/" style="font-size: 10px;">Github Actions</a> <a href="../../../../tags/HDFS/" style="font-size: 10px;">HDFS</a> <a href="../../../../tags/HTTP/" style="font-size: 11.67px;">HTTP</a> <a href="../../../../tags/Hadoop/" style="font-size: 18.33px;">Hadoop</a> <a href="../../../../tags/Hexo/" style="font-size: 10px;">Hexo</a> <a href="../../../../tags/Idea/" style="font-size: 10px;">Idea</a> <a href="../../../../tags/JVM/" style="font-size: 18.33px;">JVM</a> <a href="../../../../tags/Java/" style="font-size: 20px;">Java</a> <a href="../../../../tags/JavaScript/" style="font-size: 16.67px;">JavaScript</a> <a href="../../../../tags/Linux/" style="font-size: 15px;">Linux</a> <a href="../../../../tags/MapReduce/" style="font-size: 11.67px;">MapReduce</a> <a href="../../../../tags/Markdown/" style="font-size: 10px;">Markdown</a> <a href="../../../../tags/Maven/" style="font-size: 13.33px;">Maven</a> <a href="../../../../tags/Node/" style="font-size: 10px;">Node</a> <a href="../../../../tags/Node-js/" style="font-size: 10px;">Node.js</a> <a href="../../../../tags/SQL/" style="font-size: 13.33px;">SQL</a> <a href="../../../../tags/Serial-Port/" style="font-size: 10px;">Serial Port</a> <a href="../../../../tags/Shell/" style="font-size: 11.67px;">Shell</a> <a href="../../../../tags/SpringBoot/" style="font-size: 10px;">SpringBoot</a> <a href="../../../../tags/TCP/" style="font-size: 10px;">TCP</a> <a href="../../../../tags/VSCode/" style="font-size: 10px;">VSCode</a> <a href="../../../../tags/Vue/" style="font-size: 10px;">Vue</a> <a href="../../../../tags/WebSocket/" style="font-size: 11.67px;">WebSocket</a> <a href="../../../../tags/YARN/" style="font-size: 10px;">YARN</a> <a href="../../../../tags/hexo/" style="font-size: 11.67px;">hexo</a> <a href="../../../../tags/macOS/" style="font-size: 11.67px;">macOS</a> <a href="../../../../tags/ssh/" style="font-size: 11.67px;">ssh</a> <a href="../../../../tags/%E4%B8%AD%E6%96%87%E4%B9%B1%E7%A0%81/" style="font-size: 10px;">中文乱码</a> <a href="../../../../tags/%E5%A4%A7%E6%95%B0%E6%8D%AE/" style="font-size: 10px;">大数据</a> <a href="../../../../tags/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/" style="font-size: 10px;">安装教程</a> <a href="../../../../tags/%E5%AF%86%E9%92%A5/" style="font-size: 10px;">密钥</a> <a href="../../../../tags/%E5%B9%B6%E8%A1%8C%E7%BC%96%E7%A8%8B/" style="font-size: 10px;">并行编程</a> <a href="../../../../tags/%E6%95%B0%E6%8D%AE%E5%BA%93/" style="font-size: 10px;">数据库</a> <a href="../../../../tags/%E7%94%B5%E8%84%91/" style="font-size: 11.67px;">电脑</a> <a href="../../../../tags/%E7%AB%B9%E4%BA%91/" style="font-size: 11.67px;">竹云</a> <a href="../../../../tags/%E7%BB%88%E7%AB%AF/" style="font-size: 13.33px;">终端</a> <a href="../../../../tags/%E8%84%9A%E6%9C%AC/" style="font-size: 10px;">脚本</a> <a href="../../../../tags/%E8%BD%AC%E8%BD%BD/" style="font-size: 10px;">转载</a> <a href="../../../../tags/%E8%BD%AF%E4%BB%B6/" style="font-size: 10px;">软件</a>
    </div>
  </div>

  
    
  <div class="widget-box">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2023/02/">二月 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2023/01/">一月 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2022/11/">十一月 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2022/09/">九月 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2022/08/">八月 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2021/12/">十二月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2021/02/">二月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2021/01/">一月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/08/">八月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/07/">七月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/06/">六月 2020</a></li></ul>
    </div>
  </div>

  
    
  <div class="widget-box">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="../../../../2023/02/13/%E4%BD%BF%E7%94%A8Node-js%E5%90%8E%E5%8F%B0%E8%AF%BB%E5%8F%96%E4%B8%B2%E5%8F%A3%E6%95%B0%E6%8D%AE%E5%B9%B6%E9%80%9A%E8%BF%87WebSocket%E5%AE%9E%E6%97%B6%E6%98%BE%E7%A4%BA%E5%9C%A8%E7%BD%91%E9%A1%B5%E4%B8%8A/">使用Node.js后台读取串口数据并通过WebSocket实时显示在网页上</a>
          </li>
        
          <li>
            <a href="../../../../2023/02/09/%E4%BD%9C%E4%B8%BA%E7%94%A8%E6%88%B7%EF%BC%8C%E4%BF%AE%E6%94%B9Cookie%E6%9C%89%E6%95%88%E6%9C%9F%EF%BC%8C%E5%BB%B6%E9%95%BFCookie%E6%9C%9F%E9%99%90/">作为用户，修改Cookie有效期，延长Cookie期限</a>
          </li>
        
          <li>
            <a href="../../../../2023/02/08/%E7%BB%88%E7%AB%AF%E5%91%BD%E4%BB%A4%E4%BB%A3%E7%90%86/">终端命令网络设置</a>
          </li>
        
          <li>
            <a href="../../../../2023/01/18/Windows%E7%B3%BB%E7%BB%9FC%E7%9B%98%E6%B8%85%E7%90%86%E5%B7%A5%E5%85%B7FreeMove%E5%8F%8A%E6%96%87%E4%BB%B6%E5%8D%A0%E7%94%A8%E8%BF%9B%E7%A8%8B%E6%9F%A5%E7%9C%8B%E8%BD%AF%E4%BB%B6LockHunter%E9%85%8D%E5%90%88%E4%BD%BF%E7%94%A8/">Windows系统C盘清理工具FreeMove及文件占用进程查看软件LockHunter配合使用</a>
          </li>
        
          <li>
            <a href="../../../../2023/01/14/AutoReconnectWiFi/">检测断网自动重连WiFi脚本</a>
          </li>
        
      </ul>
    </div>
  </div>

  
      <div class="widget-box">
    <h3 class="widget-title">友链</h3>
    <div class="widget">
      
        <!-- <a style="display: block;" href="../../../../https:/xiaoyan94.github.io/" title target='_blank' -->
        <a style="display: block;" href="https://xiaoyan94.github.io/" title target='_blank'
        >Github Pages</a>
      
        <!-- <a style="display: block;" href="../../../../https:/xy94.gitee.io/" title target='_blank' -->
        <a style="display: block;" href="https://xy94.gitee.io/" title target='_blank'
        >Gitee Pages</a>
      
    </div>
  </div>

  
 
  
</aside>
      </div>
      <footer id="footer">
  <div class="foot-box global-width center">
    &copy; 2023 许嵩老公 &nbsp;&nbsp;
    Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    &nbsp;|&nbsp;主题 <a href="https://github.com/yiluyanxia/hexo-theme-antiquity" target="_blank" rel="noopener">antiquity</a>
    <br>
    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span id="busuanzi_container_site_pv">不蒜子告之   阁下是第<span id="busuanzi_value_site_pv"></span>个访客</span>
    
  </div>
  
  <!--引入文字点击特效-->
  <script src="https://code.jquery.com/jquery-2.0.3.min.js"></script>
  
<script src="../../../../js/dianji.js"></script>

</footer>

<!--添加回到顶部按钮-->
<style>
/* 小猫置顶 */
/* 自定义回到顶部样式 */
.cd-top {
  position: fixed;
  right: 25px;
  top: -900px;
  z-index: 99;
  width: 70px;
  height: 900px;
  /* background: url(https://cdn.jsdelivr.net/gh/moezx/cdn@3.1.9/img/Sakura/images/scroll.png) no-repeat center; */
  background: url(/images/scroll.png) no-repeat center;
  background-size: contain;
  -webkit-transition: all .5s ease-in-out;
  transition: all .5s ease-in-out;
  /* cursor: url(https://cdn.jsdelivr.net/gh/moezx/cdn@3.1.9/img/Sakura/cursor/No_Disponible.cur), auto; */
  cursor: url(/images/cursor/No_Disponible.cur), auto;
  opacity: 1
}

.cd-top.cd-is-visible {
  opacity: 1;
  top: -326px
}

.cd-top.cd-fade-out {
  opacity: 1
}

.cd-top:hover {
  opacity: 1
}

.cd-top span {
  display: none;
  color: #000;
  position: absolute;
  bottom: 0;
  height: 20px;
  width: 50px;
  text-align: center
}

@media screen and (max-width:860px) {
  .cd-top {
      display: none;
      height: 60px;
      width: 50px
  }
  .cd-top span {
      height: 10px;
      width: 50px
  }
}

#moblieGoTop {
  display: none;
  position: fixed;
  bottom: 10px;
  right: 10px;
  z-index: 99;
  border: 0;
  outline: 0;
  background-color: #fff;
  color: #404040;
  cursor: pointer;
  padding: 15px;
  border-radius: 10px;
  border-radius: 12px;
  box-shadow: 0 0 2px 0 rgba(0, 0, 0, .12), 0 2px 2px 0 rgba(0, 0, 0, .24);
  transition: box-shadow .2s ease
}
#moblieGoTop:hover {
  background-color: #fff;
  opacity: .8
}
.changeSkin-gear {
  position: fixed;
  bottom: 0;
  left: auto;
  right: 5px;
  width: auto;
  height: auto;
  z-index: 99;
  white-space: nowrap;
  padding: 10px 10px;
  cursor: pointer;
  border-radius: 10px 10px 0 0
}
</style>

<!-- 添加小猫置顶 -->
<a class="cd-top faa-float animated cd-is-visible cd-fade-out" style="top: -500px;"></a>
<button id="moblieGoTop" title="Go to top" style="display: none;font-size: xx-large;"><i class="fa fa-chevron-up" aria-hidden="true"></i>🔝</button>

<!-- <div class="scroll "> <i class="fa fa-arrow-up" style="margin-left: 4px;"></i>
Top⬆️
<span class="scrollpercent" style="margin-left: -2px;"></span>
<span style="margin-right: 4px; margin-left: -4px;">%</span>
</div> -->

<!-- https://www.huangpinke.com/2018/08/24/add-back-to-top-button.html -->
      <script src="https://code.jquery.com/jquery-2.0.3.min.js"></script>
<script>
if (!window.jQuery) {
var script = document.createElement('script');
script.src = "/js/jquery-2.0.3.min.js";
document.body.write(script);
}
</script>

  
<link rel="stylesheet" href="../../../../fancybox/jquery.fancybox.css">

  
<script src="../../../../fancybox/jquery.fancybox.pack.js"></script>




<script src="../../../../js/script.js"></script>




<script>
  (function(){
      var bp = document.createElement('script');
      bp.src = '//push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
  })();
  </script>

<!-- mermaid图 -->

  <script src='https://unpkg.com/mermaid@7.1.2/dist/mermaid.min.js'></script>
  <script>
    if (window.mermaid) {
      mermaid.initialize({theme: 'forest'});
    }
  </script>

    </div>
    <nav id="mobile-nav" class="mobile-nav-box">
  <div class="mobile-nav-img mobile-nav-top"></div>
  
    <a href="../../../../index.html" class="mobile-nav-link">首页</a>
  
    <a href="../../../../archives" class="mobile-nav-link">归档</a>
  
    <a href="../../../../quick-notes" class="mobile-nav-link">小抄</a>
  
    <a href="../../../../about" class="mobile-nav-link">关于</a>
  
  <div class="mobile-nav-img  mobile-nav-bottom"></div>
</nav>    
  </div>
</body>

</html>